<%-- 
    Document   : index
    Created on : Jul 4, 2013, 9:02:25 PM
    Author     : IK
--%>

<%@page import="java.util.Collection"%>
<%@page import="javax.naming.*"%>
<%@page import="com.kogent.ejb.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%!    private CartBeanRemote cart;

    public void jspInit() {
        try {
            InitialContext c = new InitialContext();
            cart = (CartBeanRemote) c.lookup("java:comp/env/ejb/CartBean");
        } catch (NamingException ex) {
        }
    }

    public void jspDestroy() {
        cart = null;
    }
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>A Stateful session bean implementation.</title>
        <link rel="stylesheet" href="mystyle.css" type="text/css"/>
    </head>
    <body bgcolor="white">
        <h1>Shopping cart</h1>
        <hr>
        <h3>Adding items to Shopping Cart</h3>
        <form method="GET">
            Enter item Name: <input type="text" name="item" size="15"/><br/>
            <input type="submit" value="Add item"/>
        </form>

        <%
            String item = request.getParameter("item");
            if (item != null) {
                cart.addItem(item);
            }

            Collection items = cart.getItems();

        %>
        <p>
            <%=items%>
        </p>
    </body>
</html>
